/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 sound.h

	$Header: /heroes4/sound.h $

	$NoKeywords: $

 ************************************************************************/

#if !defined( SOUND_H_INCLUDED )
#define SOUND_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <iosfwd>
#include "playing_sound_ptr.h"
#include "resource_traits.h"
#include "sound_stream_ptr.h"

// -------------------------------------------------------
// common interface for .WAV and .MP3 data
// -------------------------------------------------------
class t_sound_header
{
public:
	t_sound_header();

	enum { k_version = 0 };

	int		get_bits_per_sample() const;
	int		get_channels() const;
	int     get_priority() const;
	int		get_samples_per_second() const;
	int		get_size() const;
	virtual bool	read( std::streambuf& stream );
	void    set_priority( int arg );
protected:
	int		m_bits_per_sample;
	int		m_channels;
	int     m_priority;
	int		m_samples_per_second;
	int		m_size;
};

inline int t_sound_header::get_bits_per_sample() const
{
	return m_bits_per_sample;
}

inline int t_sound_header::get_channels() const
{
	return m_channels;
}

inline int t_sound_header::get_priority() const
{
	return m_priority;
}

inline int t_sound_header::get_samples_per_second() const
{
	return m_samples_per_second;
}

inline int t_sound_header::get_size() const
{
	return m_size;
}

inline void t_sound_header::set_priority( int arg )
{
	m_priority = arg;
}

// -------------------------------------------------------
// common interface for .WAV and .MP3 data
// -------------------------------------------------------

class t_abstract_sound : public t_counted_object, public t_sound_header
{
public:

	virtual char const*         get_extension() const = 0;
	virtual t_sound_stream_ptr  get_stream() const = 0;
	virtual bool				is_mp3() const = 0;
};

class t_playing_sound;

// ------------------------------------------------------
// sound object
// ------------------------------------------------------
class t_sound : public t_counted_ptr<t_abstract_sound>
{
public:
	t_sound( t_abstract_sound* sound );

	t_playing_sound_ptr play( int volume, bool looping = false, bool fade_in = false ) const;

};

inline t_sound::t_sound( t_abstract_sound* sound )
              : t_counted_ptr<t_abstract_sound>( sound )
{
}

template <>
struct t_resource_traits<t_sound>
{
	static char const prefix[];
	static char const wave_extension[];
	static char const mp3_extension[];
};

int get_millibel_volume( int linear_volume );
int get_linear_volume( int millibel_volume ); // 0 to 100%

void	stop_all_sounds();

#endif // ABSTRACT_SOUND_H_INCLUDED